<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:1px;">
  <t:datagrid name="cbsDeliverEquipmentList" checkbox="true" fitColumns="false" title="发货备件信息" actionUrl="cbsDeliverEquipmentController.do?datagrid" sortOrder="asc" sortName="" idField="id" fit="true" queryMode="group">
   <t:dgCol title="主键"  field="id"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="发货单号"  field="deliverId.code"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备件申请单号"  field="deliverId.equipmentApplyId.recordId"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="CR"  field="deliverId.crCode"    queryMode="single"  width="120" sortable="true"></t:dgCol>
   <t:dgCol title="SO"  field="deliverId.soCode"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备件类型"  field="typeId.typeDesc"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备件号"  field="itemId.item"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="数量"  field="total"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备件序列号SN"  field="sn"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="申请优先级"  field="applyLayer"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流"  field="deliverId.deliverLogistics"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创单时间"  field="deliverId.createDate"    queryMode="single"  width="120" sortable="true"></t:dgCol>
   <t:dgCol title="CSA发货时间"  field="deliverId.CSASendTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流发货时间"  field="deliverId.logisticsSendTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="预计到货时间"  field="deliverId.expectTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="签收时间"  field="deliverId.getTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流时长"  field="deliverId.logisticsDuration"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="是否达标"  field="deliverId.isStandard"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="发货单状态"  field="deliverId.status"    queryMode="single"  width="120" sortable="true"></t:dgCol>
   <t:dgCol title="是否返回"  field="isReturn"    queryMode="single" hidden="true"  width="120"></t:dgCol>
   <t:dgCol title="备件说明"  field="memo" hidden="true"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创建人名称"  field="createName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创建人登录名称"  field="createBy"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新人名称"  field="updateName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新人登录名称"  field="updateBy"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创建日期"  field="createDate" formatter="yyyy-MM-dd" hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新日期"  field="updateDate" formatter="yyyy-MM-dd" hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="操作" field="opt" width="100"></t:dgCol>
   <t:dgDelOpt title="删除" url="cbsDeliverEquipmentController.do?doDel&id={id}" />
   <t:dgToolBar title="CSA发货" icon="icon-add"  funname="CSAadd"></t:dgToolBar>
   <t:dgToolBar title="合并发货" icon="icon-add"  funname="sendTogether"></t:dgToolBar>
   <t:dgToolBar title="物流发货" icon="icon-add"  funname="sendWl"></t:dgToolBar>
   <t:dgToolBar title="新建发货单" icon="icon-add"  funname="addCreateTab"></t:dgToolBar>
   <t:dgToolBar title="编辑" icon="icon-edit"  funname="addUpdateTab"></t:dgToolBar>
   <t:dgToolBar title="批量删除"  icon="icon-remove" url="cbsDeliverEquipmentController.do?doBatchDel" funname="deleteALLSelect"></t:dgToolBar>
   <t:dgToolBar title="查看" icon="icon-search" funname="addDetailTab"></t:dgToolBar>
   <t:dgToolBar title="导入" icon="icon-put" funname="ImportXls"></t:dgToolBar>
   <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
   <t:dgToolBar title="模板下载" icon="icon-putout" funname="ExportXlsByT"></t:dgToolBar>
  </t:datagrid>
  </div>
 </div>
 <script src = "webpage/com/zybk/org.jeecgframework/cbsDeliverEquipmentList.js"></script>		
 <script type="text/javascript">
 $(document).ready(function(){
 		//给时间控件加上样式
 			$("#cbsDeliverEquipmentListtb").find("input[name='createDate']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
 			$("#cbsDeliverEquipmentListtb").find("input[name='updateDate']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
 });
 function CSAadd() {
     var datas = $("#cbsDeliverEquipmentList").datagrid("getSelections");
     if(datas.length != 1){
         tip("请选择一条信息");
         return;
     }
     var id = datas[0].id;
     addOneTab('CSA发货', 'cbsDelinerController.do?CSADeliner&id='+id, '');
 }
 function sendWl() {
     var datas = $("#cbsDeliverEquipmentList").datagrid("getSelections");
     if(datas.length != 1){
         tip("请选择一条信息");
         return;
     }
     var id = datas[0].id;
     addOneTab('物流发货', 'cbsDelinerController.do?sendLogistics&id='+id, '');
 }
 function sendTogether() {
     var ids = [];
     var datas = $("#cbsDeliverEquipmentList").datagrid("getSelections");
     var tempDatas =[];
     var zts = [];
     var users = [];
     var phones = [];
     var addresses=[];
     var statuses = [];
     var deliverTypes = [];
     var isdeliverType = true;
     var isStaus=true;
     var isAddress = true;
     var isPhone = true;
     var isUser =true;
     var isTrue = true;
     var isZt = true;
     if (datas.length>1){
         for ( var i = 0; i < datas.length; i++) {
             tempDatas.push(datas[i].crCode);
             ids.push(datas[i].id);
             zts.push(datas[i].zt);
             users.push(datas[i].userName);
             phones.push(datas[i].phone);
             deliverTypes.push(datas[i].deliverType);
             addresses.push(datas[i].address);
             statuses.push(datas[i].status);
         }
         var sendIds = ids.toString();
         sendIds=decodeURI(sendIds);
         for (var i=0;i<tempDatas.length;i++){
             if(tempDatas.indexOf(tempDatas[i])!=0){
                 isTrue = false;
                 break;
             }
         }
         for (var i=0;i<zts.length;i++){
             if(zts.indexOf(zts[i])!=0){
                 isZt = false;
                 break;
             }
         }
         for (var i=0;i<users.length;i++){
             if(users.indexOf(users[i])!=0){
                 isUser = false;
                 break;
             }
         }
         for (var i=0;i<phones.length;i++){
             if(phones.indexOf(phones[i])!=0){
                 isPhone = false;
                 break;
             }
         }
         for (var i=0;i<deliverTypes.length;i++){
             if(deliverTypes.indexOf(deliverTypes[i])!=0){
                 isdeliverType = false;
                 break;
             }
         }
         for (var i=0;i<addresses.length;i++){
             if(addresses.indexOf(addresses[i])!=0){
                 isAddress = false;
                 break;
             }
         }
         for (var i=0;i<statuses.length;i++){
             if(statuses.indexOf(statuses[i])!=0){
                 isStaus = false;
                 break;
             }else{
                 if(statuses[0]!=1 && statuses[0]!=4){
                     alert("发货单的状态均为“CSA待发货”或“欠货中”");
                     return false;
                 }
             }
         }
         if (isTrue==false){
             alert("CR不一致");
             return false;
         }else if(isZt==false){
             alert("请检查自提是否一致");
             return false;
         }else if(isUser==false){
             alert("收货人姓名不一致");
             return false;
         }else if(isAddress==false){
             alert("收货地址不一致");
             return false;
         }else if(isStaus==false){
             alert("发货单状态不一致");
             return false;
         }else if(isdeliverType==false){
             alert("发货单类型不一致");
             return false;
         }
         $.dialog.confirm('确定要合并发货吗?', function(r) {
             if(r){
                 addOneTab('CSA合并发货', 'cbsDelinerController.do?sendTogether&ids='+ids, '');

             }
         });
     }

 }
 function addCreateTab() {
     addOneTab('新建发货单', 'cbsDelinerController.do?goAdd', '');
 }
 function addUpdateTab(){
     var datas = $("#cbsDeliverEquipmentList").datagrid("getSelections");
     if(datas.length != 1){
         tip("请选择一条发货单");
         return;
     }
     var id = datas[0].id;
     var sn = datas[0].sn;
     addOneTab("编辑","cbsDelinerController.do?goUpdate&id="+id+"&sn="+sn,"");
 }
 function addDetailTab(){
     var datas = $("#cbsDeliverEquipmentList").datagrid("getSelections");
     if(datas.length != 1){
         tip("请选择一条发货单");
         return;
     }
     var id = datas[0].id;
     var sn = datas[0].sn;
     addOneTab("查看","cbsDelinerController.do?goUpdate&id="+id+"&sn="+sn,"");
 }
//导入
function ImportXls() {
	openuploadwin('Excel导入', 'cbsDeliverEquipmentController.do?upload', "cbsDeliverEquipmentList");
}

//导出
function ExportXls() {
	JeecgExcelExport("cbsDeliverEquipmentController.do?exportXls","cbsDeliverEquipmentList");
}

//模板下载
function ExportXlsByT() {
	JeecgExcelExport("cbsDeliverEquipmentController.do?exportXlsByT","cbsDeliverEquipmentList");
}
 </script>